<template>
  <div class="y-h-full y-w-full y-flex y-flex-col">
    <yyForm @search="search" v-if="formConfig.formColumn && formConfig.formColumn.length" v-bind="formConfig" v-model="formData" @toggleExpandMore="toggleExpandMore" />
    <div class=" y-pt-4 y-text-center" v-if="formConfig.formManagerColumn && formConfig.formManagerColumn.length">
      <el-button v-for="item in formConfig.formManagerColumn" :key="item.prop" v-bind="item" @click="item.onClick && item.onClick(item)">{{ item.label }}</el-button>
    </div>
    <yyTablePagination ref="yyTablePaginationRef" v-on="$listeners" class="y-flex-1 y-mt-3" v-bind="tableConfig" :params="formData">
      <template #[slotName]="{row}" v-for="slotName of Object.keys($scopedSlots)">
        <slot :name="slotName" :row="row"></slot>
      </template>
    </yyTablePagination>
  </div>
</template>

<script>
import yyForm from "@/components/yyForm/index.vue";
import yyTablePagination from "@/components/yyTablePagination/index.vue";
export default {
  props: {
    tableConfig: {
      type: Object,
      default: () => {
        return {};
      },
    },
    formConfig: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  name: "yyFormTablePagination",
  components: { yyForm, yyTablePagination },
  data() {
    return {
      formData: {},
    };
  },
  methods: {
    setFormData(key, value) {
      this.formData[key] = value;
    },
    toggleExpandMore() {
      this.$refs.yyTablePaginationRef.$refs.tableRef.doLayout();
    },
    getCheckMap() {
      return this.$refs.yyTablePaginationRef.getCheckMap();
    },
    getCheckKeys() {
      const resMap = this.getCheckMap();
      const keys = [];
      if (resMap) {
        for (let id of resMap.keys()) {
          keys.push(id);
        }
      }
      return keys;
    },
    getCheckValues() {
      const resMap = this.getCheckMap();
      const values = [];
      if (resMap) {
        for (let id of resMap.values()) {
          values.push(id);
        }
      }
      return values;
    },
    search() {
      this.$refs.yyTablePaginationRef.refresh();
    },
    restoreSelections() {
      this.$refs.yyTablePaginationRef.restoreSelections();
    },
    clearSelection() {
      this.$refs.yyTablePaginationRef.clearSelection();
    },
    /**
     * 设置默认跨页选中
     * @param rowKeyObjArr
     */
    setDefaultCorssPageMap(rowKeyObjArr) {
      this.$refs.yyTablePaginationRef.setDefaultCorssPageMap(rowKeyObjArr);
    },
  },
  mounted() {
  },
};
</script>

<style>
</style>